<template>
	<view style="padding-top: 20upx;">
		<view class="address">
			<view v-if="data.addressid == 0" style="text-align: center;padding: 30upx 0;" @click="addAddr">
				<image src="../../../static/add.png" mode="" style="width: 32upx;height: 32upx;position: relative;top: 4upx;margin-right: 6upx;"></image>
				<text style="line-height: 52upx;">添加收货地址</text>
			</view>
			<view v-else class="webkit mid" style="padding: 30upx 24upx;padding-right: 50upx;" @click="open">
				<image src="../../../static/dingwei.png" mode="" style="width: 32upx;height: 32upx;margin-right: 20upx;"></image>
				<view class="flex">
					<view v-if="address.realname">收货人： {{address.realname}}&nbsp;&nbsp;&nbsp;&nbsp;{{address.mobile}}</view>
					<view style="font-size: 26upx;color: #666;line-height: 40upx;"	v-if="address.province">{{address.province}}{{address.city}}{{address.area}}&nbsp;&nbsp;{{address.street}}&nbsp;&nbsp;{{address.address}}</view>
				</view>
			</view>
		</view>
		<view class="goods" style="margin-top: 20upx;">
			<view v-for="(items,i) in res.goods_list" :key="i">
				<view v-for="(item,J) in items.goods" :key="J" style="padding: 20upx 24upx;background: #fff;border-bottom: 1px solid #e2e2e2;">
					<view class="webkit">
						<image :src="item.thumb" style="width: 160upx;height: 160upx;margin-right: 24upx;"></image>
						<view class="flex">
							<view style="line-height: 40upx;height: 80upx;" v-if="item.title">{{item.title}}</view>
							<view style="color: #999;height: 40upx;">
								<view v-if="item.optionid != 0" style="font-size: 26upx;">{{item.optiontitle}}</view>
							</view>
							<!-- <view style="font-size: 24upx;color: #C0C0C0;text-decoration: line-through;padding-left: 8upx;font-weight: normal;">&yen;{{item.productprice}}</view> -->
						</view>
						<view style="margin-left: 20upx;padding-top: 10upx;">
							<view style="color: #f55;font-size: 28upx;text-align: right;" v-if="item.marketprice">&yen;{{item.marketprice}}</view>
							<view style="font-size: 26upx;color: #999;text-align: right;" v-if="item.total">x{{item.total}}</view>
							
							<view style="position: relative;" v-if="item.paramss">
								<text @click="show_time" style="color: #FF0000;" v-if="time_rate">{{time_rate}}</text>
								<view :style="{ display: time_status }"  style="width: 365upx;position: absolute;top: 40upx;right: 0upx;min-height: 60upx;line-height: 60upx;background: #fff;">
									<view style="height: 60upx;line-height: 60upx;" v-for="(time,Q) in item.paramss" :key="Q" @click="hide_time(time.day,time.rate)">
										{{time.day}}天后发货,折扣{{time.rate}}%
									</view>
								</view>
							</view>
							
						</view>
					</view>
					<!-- <view style="color:red;text-align: center;font-size: 24upx;margin-top: 20upx;margin-bottom: 16upx;">请选择具体支付方式，默认全部现金支付</view>
					<view style="position: relative;">
						<button type="default" @click="select" :data-id="item.goodsid" style="background: #fff;font-size: 28upx;text-align: left;">{{item.text}}</button>
						<image src="../../../static/select.png" style="width: 32upx;height: 32upx;position: absolute;top: 20upx;right: 20upx;" mode=""></image>
					</view> -->
				</view>
			</view>
		</view>
		<view style="background: #fff;padding: 20upx 24upx;">
			<view>共<text style="color: #f55;" v-if="res.total">{{res.total}}</text>件商品</view>
			<view>需付：</view>
			<view v-if="jfdk > 0" style="text-align: right;font-size: 32upx;color: #f00;">{{jfdk}}个优惠积分</view>
			<view style="text-align: right;font-size: 32upx;color: #f00;" v-if="price">&yen;{{price}}</view>
			<view class="webkit" v-for="(item,index) in cointext" :key="index">
				<view v-if="item">{{index}}</view>
				<view class="flex" style="text-align: right;color: #666;" v-if="item">{{item}}个</view>
			</view>
		</view>
		<view class="webkit" style="background: #fff;margin-top: 10px;padding: 10px 12px;">
			<view style="width: 150upx;">买家留言</view>
			<textarea placeholder="50字以内(选填)" @blur="textarea" maxlength="50" style="font-size: 26upx;padding-top: 10upx;line-height: 40upx;height: 120upx;"/>
		</view>
		
		<!-- <view class="content">
			<button type="primary" @click="openType0">开启type=0的actionSheet</button>
			<button type="primary" @click="openType1">开启type=1的actionSheet</button>
			<action ref="action" @itemClick="itemClick" @titleClick="titleClick"></action>
		</view> -->
		
		
		<view class="uni-list">
			<!-- <view style="height: 100upx;line-height: 100upx;background-color: #FFFFFF;display: flex;margin: 0 30upx;">
				<text style="flex: 5;">素米最高抵用数量</text>
				<text style="flex: 1;text-align: right;">{{jddk}}</text>
			</view> -->
      <radio-group @change="radioChange">
				
				<!-- <view :style="{display:show_input0}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[0].name}}</view>
						<view class="val1" v-cloak>- ¥ {{val1}}</view>
						<view>
						    <radio value='0' :checked="current === 0" />
						</view>
					</label>
				</view> -->
				
				<!-- <view :style="{display:show_input1}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[1].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input1}">
							<input class="uni-input" placeholder="请输入收益抵扣数量" type="text" v-model="tongduibao" @input="input1"/>
						</view>
						<view>
						    <radio value='1' :checked="current === 1" @click="showing_input1" />
						</view>
					</label>
				</view> -->
				<!-- <view :style="{display:show_input2}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view style="width: 200upx;">{{items[2].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input2}">
							<input class="uni-input" type="number" placeholder="请输入素米抵扣数量" v-model="jingdou" @input="input2" :style="{display:show_input22}"/>
						</view>
						<view>
						    <radio value='2' :checked="current === 2" @click="showing_input2" />
						</view>
					</label>
				</view> -->
				<!-- <view :style="{display:show_input3}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[3].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input3}">
							<input class="uni-input" type="number" placeholder="请输入素米抵扣数量" v-model="jingdou" @input="input3" :style="{display:show_input33}"/>
						</view>
						<view>
						    <radio value='3' :checked="current === 3" @click="showing_input3" />
						</view>
					</label>
				</view> -->
				
				<label  class="uni-list-cell uni-list-cell-pd">
					<view>运费</view>
					<view v-if="data.dispatchprice">￥{{data.dispatchprice}}</view>
				</label>
				<label  class="uni-list-cell uni-list-cell-pd">
					<view>商品小计</view>
					<view v-if="price">¥{{price}}</view>
				</label>
				
            </radio-group>
        </view>
		<view style="position: fixed;bottom: 0;width: 100%;height: 100upx;display: flex;z-index: 33;">
			<text style="flex: 5; line-height: 100upx;background-color: #fff;padding-left: 20upx;" v-if="price">需付：{{price}} 元</text>
			<button @click="submit" style="flex: 2;background-color: #EB2E15;color: #fff;line-height: 100upx;">立即支付</button>
		</view>
		<!-- 点击地址,右侧打开地址管理选项 -->
		<uni-drawer :visible="rightDrawerVisible" mode="right" @close="closeRightDrawer" style="margin-top: -20upx;">
			<view style="padding: 20upx;box-sizing: border-box;height: 100%;overflow-y: scroll;overflow-x: hidden;">
				<view v-for="(item,index) in addrlist" :key="index" style="border: 1px solid #ccc;border-radius: 10upx;padding: 12upx 20upx;margin-bottom: 20upx;" @click="choose" :data-addrid='item.id'>
					<view class="webkit">
						<view class="flex" v-if="item.realname">{{item.realname}}</view>
						<view class="del" @click="del(item.id,item)">删除</view>
					</view>
					<view>{{item.mobile}}</view>
					<view style="font-size: 26upx;line-height: 32upx;margin-top: 4upx;padding-top: 12upx;border-top: 2upx dashed #c8c8c8;color: #666;">{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.area}}</view>
					<view style="font-size: 26upx;line-height: 38upx;color: #666;" v-if="item.street">{{item.street}}&nbsp;&nbsp;{{item.address}}</view>
				</view>
				<view class="add_btn" @click="addAddr" style="text-align: center;height: 100upx;line-height: 100upx;width: 100%;color: #fff;background-color: #ff4b2b;margin-bottom: 120upx;" v-if="addrlist.length <= 3">
					<image src="../../../static/add.png" mode="" style="width: 32upx;height: 32upx;position: relative;top: 4upx;margin-right: 6upx;"></image>
					<text style="line-height: 52upx;">新增收货地址</text>
				</view>
			</view>
			
		</uni-drawer>
	</view>
</template>

<script>
	import uniDrawer from '../../../components/uni-drawer.vue';
	import action from "../../../components/shufei-action/action.vue"
	export default {
		components: {
			uniDrawer,
			action
		},
		data() {
			return {
				val1:'',
				tongduibao:0,
				jingdou:0,
				show_input0:'block',
				show_input1:'block',
				show_input2:'block',
				show_input3:'block',
				show_input22:'none',
				show_input33:'none',
				rightDrawerVisible: false,
				res:[],
				openid:'',
				data:[],
				address:[],
				addrlist:[],
				subcoin:[],
				coin:[],
				cointext:{},
				// 需要支付价格
				price:'',
				price_base:0,
				numvalue:0,
				items: [{
					value: '0',
					name: '收益全部抵扣'
				},{
					value: '1',
					name: '收益加现金'
				},{
					value: '2',
					name: '素米抵用'
				},{
					value: '3',
					name: '素米加收益'
				}],
				current: 5,
				jddk:0,
				tdb:0,
				a_kzp:0,
				credit1:0,
				a_kzp_base:0,
				jddk_base:0,
				id :'',
				fromcart :'',
				carrierid :'',
				addressid :'',
				remark :'',
				fromquick:'',
				dispatchprice :'',
				zzzf:'',
				sjzzzf:'',
				iid:'',
				optionid:'',
				total:'',
				goodsid:'',
				time_line: true,
				time_status: 'none',
				time_rate:'请选择发货时间',
				jfdk:'',
			};
		},
		onLoad:function(e){
			console.log(e)
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					if(e.id == undefined){
						this.setAjax()
					}else{
						this.setBuyAjax(e)
						this.goodsid = e.id
						this.iid = e.id
						this.optionid = e.optionid
						this.total = e.total
					}
				},
				fail: () => {
					uni.navigateBack()
				}
			});
		},
		methods:{
			openType0(){
				this.$refs.action.actionConfig={
					title:'您的账户最多可抵扣' + this.jddk,
					// jingdou: this.jingdou,
					jddk: this.jddk,
					
					// summary:'请选择取消订单原因',
					// list:['我不想买了','信息填写错误，重新拍','其他原因'],
					type:0,
					isBorderColor:false,
					specClass: 'show',
				}
			},
			// openType1(){
			// 	this.$refs.action.actionConfig={
			// 			title:'退款',
			// 			summary:'订单支付已超过30分钟原则上不能退款，如有疑问请联系客服',
			// 			type:1,
			// 			cancelColor:"#FF3D45",
			// 			isBorderColor:true,
			// 			specClass: 'show',
			// 	}
			// },
			// itemClick(index,type){
			// 		//这里根据不同的类型点击的索引值,做对应的逻辑处理
			// 		console.log(`你点击的action-sheet的类型是${type},list对应的索引值是${index}`)
			// },
			// titleClick(type){
			// 		//这里根据不同的类型做对应的逻辑处理
			// 		console.log(type)
			// },
			show_time () {
				this.time_status = 'block'
			},
			hide_time (day,rate) {
				this.price = this.price_base
				
				this.price = this.price - this.data.dispatchprice
				this.time_rate = day + '天后发货,折扣' + rate + '%'
				this.price = this.price - this.price * rate / 100 + this.data.dispatchprice
				
				this.time_status = 'none'
			},
			jingdouInput(e) {
				this.jingdou = e.target.value
				console.log(this.jingdou)
				console.log(this.jddk)
				// 输入的大于可以抵扣的
				// setTimeout(()=>{
					if(this.jingdou > this.jddk){
						this.jingdou = this.jddk
					   return
					}
				// },20)
			console.log(this.jingdou)
			},
			setBuyAjax(value){
				// console.log(value)
				uni.request({
					url:'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {
						openid:this.openid,
						id:value.id,
						optionid:value.optionid,
						total:value.total,
						},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						uni.hideLoading()
						for(var i in res.data.goods_list){
							// console.log(i)
							for(var j in res.data.goods_list[i].goods){
								res.data.goods_list[i].goods[j].text = '¥'+res.data.goods_list[i].goods[j].ggprice
							}
						}
						this.jfdk = res.data.jfdk
						this.jddk_base = this.jddk
						this.tdb = res.data.tdb
						this.a_kzp = res.data.member.a_kzp
						this.a_kzp_base = this.a_kzp
						this.credit1 = res.data.member.credit1
						this.price = res.data.realprice
						this.price_base = this.price
						
						this.res = res.data
						this.address = res.data.address
						
						if(this.a_kzp < this.price) {
							this.show_input0 = 'none'
						}
						// 没有通配宝
						if (this.a_kzp == '' || this.a_kzp == 0 || this.a_kzp == null) {
							this.show_input0 = 'none'
							this.show_input1 = 'none'
						}
						// 没有京豆
						if(this.jddk == '' || this.jddk == 0 || this.jddk == null) {
							this.show_input2 = 'none'
							this.show_input3 = 'none'
						}
						
						var dispatchprice='';
						if(res.data.exchangeOrder != ''){
							dispatchprice = res.data.exchangepostage
						}else if(res.data.taskgoodsprice != null &&res.data.taskgoodsprice != 0 &&res.data.taskgoodsprice != ''&&res.data.taskgoodsprice != null){
							dispatchprice = res.data.taskgoodsprice
						}else{
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for(var i in res.data.goods){
							price = price+Number(res.data.goods[i].ggprice)
						}
						var zzzf = '0:'+price
						
						
						var sData = '{"id":'+res.data.createInfo.id+',"fromcart":'+res.data.createInfo.fromcart+',"carrierid":'+res.data.createInfo.storeid+',"addressid":"'+res.data.createInfo.addressid+'","remark":"","fromquick":'+res.data.createInfo.fromquick+',"dispatchprice":'+dispatchprice+',"zzzf":"'+zzzf+'","sjzzzf":"'+res.data.zsjzzzf+'","openid":"'+this.openid+'"'
						for(var i in res.data.createInfo.goods){
							for(var j in res.data.createInfo.goods[i]){
								sData += ',"goods['+i+']['+j+']":"'+res.data.createInfo.goods[i][j]+'"'
							}
						}
						
						sData += '}'
						var data = JSON.parse(sData)
						this.data = data
						
						var coinid=[]
						var sjzzzf = ''
						for(var i in this.res.goods_list){
							for(var j in this.res.goods_list[i].goods){
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥'+g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
					},
					fail: () => {},
					complete: () => {}
				});
			},
			setAjax(){
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(this.a_kzp < this.price) {
							this.show_input0 = 'none'
						}
						// 没有通配宝
						if (this.a_kzp == '' || this.a_kzp == 0) {
							this.show_input0 = 'none'
							this.show_input1 = 'none'
						}
						// 没有京豆
						if(this.jddk == '' || this.jddk == 0) {
							this.show_input2 = 'none'
							this.show_input3 = 'none'
						}
						
						uni.hideLoading()
						for(var i in res.data.goods_list){
							for(var j in res.data.goods_list[i].goods){
								res.data.goods_list[i].goods[j].text = '¥'+res.data.goods_list[i].goods[j].ggprice
							}
						}
						this.price = res.data.goodsprice
						this.res = res.data
						this.address = res.data.address
						var dispatchprice='';
						if(res.data.exchangeOrder != ''){
							dispatchprice = res.data.exchangepostage
						}else if(res.data.taskgoodsprice != null &&res.data.taskgoodsprice != 0 &&res.data.taskgoodsprice != ''&&res.data.taskgoodsprice != null){
							dispatchprice = res.data.taskgoodsprice
						}else{
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for(var i in res.data.goods){
							price = price+Number(res.data.goods[i].ggprice)
						}
						var zzzf = '0:'+ price
						
						
						var sData = '{"id":'+res.data.createInfo.id+',"fromcart":'+res.data.createInfo.fromcart+',"carrierid":'+res.data.createInfo.storeid+',"addressid":"'+res.data.createInfo.addressid+'","remark":"","dispatchprice":'+dispatchprice+',"zzzf":"'+zzzf+'","sjzzzf":"'+res.data.zsjzzzf+'","openid":"'+this.openid+'"'
						for(var i in res.data.createInfo.goods){
							for(var j in res.data.createInfo.goods[i]){
								sData += ',"goods['+i+']['+j+']":"'+res.data.createInfo.goods[i][j]+'"'
							}
						}
						sData += '}'
						var data = JSON.parse(sData)
						this.data = data
						this.id = res.data.createInfo.id
						this.fromcart = res.data.createInfo.fromcart
						this.carrierid = res.data.createInfo.storeid
						this.addressid = res.data.createInfo.addressid
						this.remark = ''
						// this.fromquick = fromquick
						this.dispatchprice = dispatchprice
						this.zzzf = zzzf
						this.sjzzzf = res.data.zsjzzzf
						console.log(res.data)
						// 这里我修改了i为0,因为暂时未遇到有i= 1 的情况
						this.goods_list = res.data.goods_list[0].goods[j]
						
						this.totalprice = this.price + this.data.dispatchprice
						
						var coinid=[]
						var sjzzzf = ''
						for(var i in this.res.goods_list){
							for(var j in this.res.goods_list[i].goods){
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥'+g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
					},
					fail: () => {},
					complete: () => {}
				});
			},
			show_close(){
				this.show = true
			},
			close(){
				this.show = false
			},
			textarea(e){
				this.data.remark = e.detail.value
			},
			addAddr(){
				uni.navigateTo({
					url: '../../../pageA/member/address/post?goodsid='+this.goodsid+'&optionid='+this.optionid+'&total='+this.total
				});
			},
			open(){
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.address&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						this.addrlist = res.data
						// console.log(this.addrlist)
					},
					fail: () => {},
					complete: () => {}
				});
				this.rightDrawerVisible = !this.rightDrawerVisible
			},
			choose(e){
				if(this.data.addressid != e.currentTarget.dataset.addrid){
					uni.showLoading();
					this.data.addressid = e.currentTarget.dataset.addrid
					uni.request({
						url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.address.post&app=1&id='+e.currentTarget.dataset.addrid,
						method: 'POST',
						data: {'openid':this.openid},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: res => {
							uni.hideLoading()
							this.address = res.data
							console.log(this.address)
							this.closeRightDrawer()
						},
						fail: () => {},
						complete: () => {}
					});
				}else{
					this.closeRightDrawer()
				}
			},
			select(e){
				for(var i in this.res.goods_list){
					for(var j in this.res.goods_list[i].goods){
						var g = this.res.goods_list[i].goods[j]
						if(g.goodsid == e.currentTarget.dataset.id){
							var coinlist = [],coinid=[],asd=[];
							coinlist.push('￥'+g.ggprice)
							asd.txt = '￥'+g.ggprice
							asd.id = '0'
							asd.num = 0
							asd.price = Number(g.ggprice)
							asd.shopid = i
							asd.goodsid = g.goodsid
							asd.coinname = ''
							coinid.push(asd)
							for(var k in g.coin){
								var l = '￥'+g.xjsl+' + '+ g.coin[k].number+'个'+g.coin[k].coinname
								var cn = g.coin[k].number+'个'+g.coin[k].coinname
								coinlist.push(l)
								var a = []
								a.txt = l
								a.coinname = g.coin[k].coinname
								a.id = g.coin[k].id
								a.num = g.coin[k].number
								a.price = g.xjsl
								a.goodsid = g.goodsid
								a.shopid = i
								coinid.push(a)
							}
							uni.showActionSheet({
								itemList: coinlist,
								success: (e) => {
									for(var i in this.subcoin){
										if(this.subcoin[i].goodsid == coinid[e.tapIndex].goodsid){
											this.subcoin[i].id = coinid[e.tapIndex].id
											this.subcoin[i].num = coinid[e.tapIndex].num
											this.subcoin[i].price = coinid[e.tapIndex].price
											this.subcoin[i].txt = coinid[e.tapIndex].txt
											this.subcoin[i].coinname = coinid[e.tapIndex].coinname
										}
									}
									for(var i in this.res.goods_list){
										for(var j in this.res.goods_list[i].goods){
											if(this.res.goods_list[i].goods[j].goodsid == coinid[e.tapIndex].goodsid){
												this.res.goods_list[i].goods[j].text = coinid[e.tapIndex].txt
											}
										}
									}
									var ary ={},p = 0
									for(var i in this.subcoin){
										if(this.subcoin[i].id != 0){
											if(ary[this.subcoin[i].coinname] == undefined){
												ary[this.subcoin[i].coinname] =this.subcoin[i].num
											}else{
												ary[this.subcoin[i].coinname] += this.subcoin[i].num
											}
										}
										p += this.subcoin[i].price
									}
									this.cointext = ary
									this.price = p
								}
							})
						}
					}
				}
			},
			submit(){
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {
						openid:this.openid,
						id:this.iid,
						optionid:this.optionid,
						total:this.total,
						},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						uni.hideLoading()
						for(var i in res.data.goods_list){
							console.log(i)
							for(var j in res.data.goods_list[i].goods){
								res.data.goods_list[i].goods[j].text = '¥'+res.data.goods_list[i].goods[j].ggprice
							}
						}
						this.price = res.data.goodsprice
						this.res = res.data
						this.address = res.data.address
						var dispatchprice='';
						if(res.data.exchangeOrder != ''){
							dispatchprice = res.data.exchangepostage
						}else if(res.data.taskgoodsprice != null &&res.data.taskgoodsprice != 0 &&res.data.taskgoodsprice != ''&&res.data.taskgoodsprice != null){
							dispatchprice = res.data.taskgoodsprice
						}else{
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for(var i in res.data.goods){
							price = price+Number(res.data.goods[i].ggprice)
						}
						var zzzf = '0:'+price
						
						if(this.jingdou=="" || this.jingdou == undefined) {this.jingdou = 0}
						if(this.tongduibao=="" || this.tongduibao == undefined) {this.tongduibao = 0}
						if (this.time_rate == '请选择发货时间') { this.time_rate = ''}
						this.price = this.price + this.data.dispatchprice
						var sData = '{"id":'+res.data.createInfo.id+',"fromcart":'+res.data.createInfo.fromcart+',"carrierid":'+res.data.createInfo.storeid+',"addressid":"'+res.data.createInfo.addressid+'","remark":"","dispatchprice":'+dispatchprice+',"zzzf":"'+zzzf+'","sjzzzf":"'+res.data.zsjzzzf+'","openid":"'+this.openid+'","tongduibao":'+this.tongduibao+',"jindou":'+  '"' + this.time_rate + '"' +',"istongduibao":'+this.numvalue+',"totalprice":'+ this.price
						// + ',"ys":' + this.time_rate
						for(var i in res.data.createInfo.goods){
							for(var j in res.data.createInfo.goods[i]){
								sData += ',"goods['+i+']['+j+']":"'+res.data.createInfo.goods[i][j]+'"'
							}
						}
						sData += '}'
						var data = JSON.parse(sData)
						this.data = data
						console.log(this.data)
						
						this.id = res.data.createInfo.id
						this.fromcart = res.data.createInfo.fromcart
						this.carrierid = res.data.createInfo.storeid
						this.addressid = res.data.createInfo.addressid
						this.remark = ''
						// this.fromquick = fromquick	
						this.dispatchprice = dispatchprice
						this.zzzf = zzzf
						this.sjzzzf = res.data.zsjzzzf
						// 这里我修改了i为0,因为暂时未遇到有i= 1 的情况
						this.goods_list = res.data.goods_list[0].goods[j]
						
						var coinid=[]
						var sjzzzf = ''
						for(var i in this.res.goods_list){
							for(var j in this.res.goods_list[i].goods){
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥'+g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
						console.log(this.data)
						uni.request({
							url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.create.submit&app=1',
							method: 'POST',
							data: this.data,
							header:{'Content-Type':'application/x-www-form-urlencoded'},
							success: res => {
								
								if(res.data.status == 1){
									uni.navigateTo({
										url: '../pay/pay?id='+res.data.result.orderid
									});
								}else{
									uni.showToast({
										title: res.data.result.message.toString(),
										icon:"none"
									});
								}
							},
							fail: () => {},
							complete: () => {}
						});
					},
					fail: () => {},
					complete: () => {}
				});
				
			},
			closeRightDrawer() {
				this.rightDrawerVisible = false;
			},
			showRightDrawer() {
				this.rightDrawerVisible = true;
			},
			del(e,item) {
				// 删除
				console.log(item)
				// if()
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.address.delete&app=1',
					method: 'POST',
					data: {'openid':this.openid,'id':e},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						console.log(e)
						this.setAjax()
					},
					fail: () => {},
					complete: () => {}
				})
			},
			// 按钮改变时
			radioChange(evt) {
        for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.target.value) {
						this.current = i;
						// 全部使用收益
						if (this.current == 0) {
							this.numvalue = 1
							this.tongduibao = 0
							this.jingdou = 0
							this.jddk = this.jddk_base
							this.a_kzp = this.a_kzp_base
							this.price = this.price_base
							// 收益小于price
							if (this.tdb < this.price) {
								this.val1 = this.tdb
							} else {
								// 收益大于price
								this.val1 = this.price
							}
							// 收益剩余
							this.a_kzp = this.a_kzp - this.val1
							// 支付0
							this.price = this.price - this.val1
						}
						// 收益加现金
						if (this.current == 1) {
							this.numvalue = 2
							this.price = this.price_base
							this.tongduibao = 0
							this.jingdou = 0
						}
						// 素米抵用
						if (this.current == 2) {
							this.numvalue = 3
							this.price = this.price_base
							this.jingdou = 0
							this.show_input22 = 'block'
							this.show_input33 = 'none'
						}
						// 素米加收益
						if (this.current == 3) {
							this.numvalue = 4
							this.price = this.price_base
							this.jingdou = 0
							this.show_input22 = 'none'
							this.show_input33 = 'block'
						}
						break;
					}
				}
            },
			showing_input1() {
				this.show_input1 = 'block'
			},
			showing_input2() {
				this.show_input2 = 'block'
			},
			showing_input3() {
				this.show_input3 = 'block'
			},
			// 收益加现金
			input1() {
				setTimeout(()=> {
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					this.price = this.price - this.tongduibao
					
					// 如果总收益数量大于price
					if (this.a_kzp > this.price) {
						// 输入了收益
						if (this.tongduibao) {
							// 输入收益小于价格
							if(this.tongduibao < this.price_base) {
								// 重置
								this.price = this.price_base
								this.price = this.price - this.tongduibao
							}
							// 输入收益大于价格
							else {
								uni.showToast({
									title: '收益要不到那么多哦~',
									icon: "none",
								});
								setTimeout(()=> {
									this.price = this.price_base
									this.tongduibao = this.price_base
									this.price = this.price - this.tongduibao
								},200) 
							}
						}
						else {
							// 没有输入收益
							 uni.showToast({
								title: '请输入收益抵扣数量',
								icon: "none",
								success:() =>{
									this.price = this.price_base
								}
							 });
						 }
					}
					// 如果总收益小于price
					else {
						if(this.tongduibao){
							// 总收益小于输入的
							if(this.a_kzp < this.tongduibao){
								// 将输入的收益数改为总的收益数
								this.tongduibao = this.a_kzp
								this.price = this.price - this.tongduibao
								return
							} else {
								// 总收益大于输入的
								this.price = this.price - this.tongduibao
							}
						} 
						else {
							// 没有输入收益
							 uni.showToast({
								title: '请输入收益抵扣数量',
								icon: "none",
								success:function(){
									this.price = this.price_base
								}
							 });
						 }
					}
				},20)
				
			},
			input2(e){
				this.jingdou = e.target.value
				this.price = this.price_base
				console.log(this.jddk_base)
				setTimeout(()=>{
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					// 输入素米数大于总素米数量
					// 后台的素米抵扣已经判断过不会大于price
					if(this.jddk < this.jingdou){
						this.price = this.price_base
						this.jingdou = this.jddk
						this.price = this.price - this.jddk
					    // return
					} 
					else if(this.jingdou=='' || this.jingdou == undefined){
						this.price = this.price_base
						// this.current = 0  // 修改选顶的按钮
					} 
					else {
						// 需支付的金额
					    this.price = this.price - this.jingdou;
							this.price = this.price.toFixed(2).toString();
							console.log(this.price)
					}
					
				},20)
				
			},
			input3(){
				setTimeout(()=>{
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					//如果填写的素米数量大于可抵扣的素米数量
					if(this.jingdou > this.jddk){
						uni.showToast({
							title: '最多抵扣' + this.jddk + '素米',
							icon: "none"
						});
						this.jingdou = this.jddk
					    return
					}
					// 输入小于总素米
					else {
						this.price = this.price_base
						// 去除素米剩余price
						this.price = this.price - this.jingdou;
						this.price.toString();
						// 收益小于price
						// if (this.tdb < this.price) {
						// 	this.price = this.price - this.tdb
						// 	// 收益剩余
						// 	// this.a_kzp = this.a_kzp - this.tdb
						// } else {
						// 	// 收益大于price
						// 	this.val1 = this.price
						// }
					}
				},20)
				
			}
		}
	}
	
</script>

<style>
.val1 {
	margin-left: 280upx;
}
.uni-input {
	width: 350upx;
	margin-left: 100upx;
}
.goods_mount {
	padding-left: 30upx;
	background-color: #fff;
}
.uni-list {
	margin: 20upx 0 120upx 0;
}
.address{
	background: #fff;
	position: relative;
}
.address:after{
	content: ' ';
    position: absolute;
    left: 0;
    width: 100%;
    height: 6upx;
    background: url(../../../static/order_line.png) repeat-x;
}
.address:before{
    content: " ";
    display: inline-block;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
    height: 16upx;
    width: 16upx;
    border-width: 2upx 2upx 0 0;
    border-color: #b2b2b2;
    border-style: solid;
    position: absolute;
    top: 50%;
    margin-top: -10upx;
    right: 30upx;
}

.del {
	color: #888;
}
</style>
